import request from '@/utils/http';
import { jsonToUrlParam, getApiUrl } from '../../urlSearchParams';
import type { PagedResultDto } from '../type';
import type { TenantDto, GetTenantsInput, TenantCreateDto, TenantUpdateDto } from './type';

// Api地址
enum API {
  DEFAULT_URL = 'api/basics/tenants'
}

// 列表
export const getListAsync = (input: GetTenantsInput) => {
  const paramenter = jsonToUrlParam(input);
  const url = getApiUrl(API.DEFAULT_URL, paramenter);
  return request.get<PagedResultDto<TenantDto>>(url);
};

// 详情
export const getAsync = (id: string) => request.get<TenantDto>(`${API.DEFAULT_URL}/${id}`);

// 创建
export const createAsync = (input: TenantCreateDto) =>
  request.post<TenantDto>(API.DEFAULT_URL, input);

// 更新
export const updateAsync = (id: string, input: TenantUpdateDto) =>
  request.put<TenantDto>(`${API.DEFAULT_URL}/${id}`, input);

// 删除
export const deleteAsync = (id: string) => request.delete<void>(`${API.DEFAULT_URL}/${id}`);
